pub mod decorator;
//装饰是一种结构设计模式， 允许你通过将对象放入特殊封装对象中来为原对象增加新的行为。

trait IPancake {
    fn price(&self) -> i32;
}

struct Flavor {}

impl IPancake for Flavor {
    fn price(&self) -> i32 {
        7
    }
}

struct VeggieMania {
    pancake: Box<dyn IPancake>,
}

struct Coco {
    pancake: Box<dyn IPancake>,
}


impl IPancake for VeggieMania {
    fn price(&self) -> i32 {
        self.pancake.price() + 3
    }
}

impl IPancake for Coco {
    fn price(&self) -> i32 {
        self.pancake.price() + 3
    }
}

#[test]
fn main() {
    let flavor = Flavor {};
    println!("flavor {}", flavor.price());
    let mania = VeggieMania {
        pancake: Box::new(flavor),
    };
    println!("mania {}", mania.price());

    let coco = Coco {
        pancake: Box::new(mania),
    };
    println!("coco {}", coco.price());
}